package uit.mmt02.share;

import java.util.List;

import uit.mmt02.R;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class ShowEmailLoginAdapter extends ArrayAdapter<EmailLoginManager> 
{
	Activity context;
	List<EmailLoginManager>list;
	public ShowEmailLoginAdapter(Activity context, List<EmailLoginManager>list)
	{
		super(context,R.layout.row_email_login_manager,list);
		this.context = context;
		this.list = list;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = null;
		if(convertView == null)
		{
			LayoutInflater li = context.getLayoutInflater();
			v = li.inflate(R.layout.row_email_login_manager, null);
		}
		else
		{
			v = convertView;
		}
		
		// lay email login tai row hien tai
		final EmailLoginManager em = list.get(position);
		TextView txt_username = (TextView)v.findViewById(R.id.txt_username);
		TextView txt_newmail = (TextView)v.findViewById(R.id.txt_newmail);
		CheckBox cb_check = (CheckBox)v.findViewById(R.id.cb_adapter_check);
		cb_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CheckBox cb_temp = (CheckBox)v.findViewById(R.id.cb_adapter_check);
				if(cb_temp.isChecked())
				{
					em.setChecked(true);
				}
				else
				{
					em.setChecked(false);
				}
				
			}
		});
		
		txt_username.setText(em.getUsername());
		txt_newmail.setText(String.valueOf(em.getNewmail()));
		cb_check.setChecked(em.isChecked());
//		return super.getView(position, convertView, parent);
		v.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				Toast.makeText(context, "click ckick", Toast.LENGTH_SHORT).show();
				v.setBackgroundColor(Color.CYAN);
			}
		});
		return v;
	}

}
